package com.sixmac.emchat.test;

/**
 * Created by clay on 2018/3/5 13:50.
 */

import com.google.gson.GsonBuilder;
import com.sixmac.emchat.api.impl.EasemobSendMessage;
import io.swagger.client.model.Msg;
import io.swagger.client.model.MsgContent;
import io.swagger.client.model.UserName;

import java.util.HashMap;
import java.util.Map;

/**
 * emchat发送消息工具类
 */
public class EmchatUtil {
    private static EasemobSendMessage easemobSendMessage = new EasemobSendMessage();
    public static void sendText(String  content,String msgSender,String msgReceiver ) {
        Msg msg = new Msg();
        MsgContent msgContent = new MsgContent();
        msgContent.type(MsgContent.TypeEnum.TXT).msg(content);
        UserName userName = new UserName();
        userName.add(msgReceiver);
        Map<String,Object> ext = new HashMap<>();
        ext.put("test_key","test_value");
        msg.from(msgSender).target(userName).targetType("users").msg(msgContent).ext(ext);
        System.out.println(new GsonBuilder().create().toJson(msg));
        Object result = easemobSendMessage.sendMessage(msg);
        System.out.println(result);
    }
}
